<?php
/**
 * DouPHP
 * --------------------------------------------------------------------------------------------------
 * 版权所有 2013-2015 漳州豆壳网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.douco.com
 * --------------------------------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在遵守授权协议前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 * 授权协议：http://www.douco.com/license.html
 * --------------------------------------------------------------------------------------------------
 * Author: DouCo
 * Release Date: 2015-10-16
 */
define('IN_DOUCO', true);

require (dirname(__FILE__) . '/include/init.php');

// rec操作项的初始化
$rec = $check->is_rec($_REQUEST['rec']) ? $_REQUEST['rec'] : 'default';

$smarty->assign('rec', $rec);
$smarty->assign('cur', 'order_booking');
/**
 * +----------------------------------------------------------
 * 订单列表
 * +----------------------------------------------------------
 */
if ($rec == 'default') {
    $smarty->assign('ur_here', $_LANG['order_booking']);
    //fliter-----//
    $noon_state  = $_REQUEST['noon_state'];
    $night_state = $_REQUEST['night_state'];
    $order_no    = $_REQUEST['order_no'];
    $bookdate    = $_REQUEST['bookdate'];
    $where = " WHERE 1 AND o.paystate='1' ";  //已支付

    if($noon_state != '')
        $where .=  " AND ob.noon_state='$noon_state'";
        $get   .= '&noon_state=' . $noon_state;
    if($night_state != '')
        $where .=  " AND ob.night_state='$night_state'";
        $get   .= '&night_state=' . $night_state;        
    if($order_no != '')
        $where .=  " AND ob.order_no='$order_no' ";
        $get   .= '&order_no=' . $order_no;
    if($bookdate != '')
        $where .=  " AND ob.bookdate REGEXP('$bookdate') ";
        $get   .= '&bookdate=' . $bookdate;

    $sql = "SELECT ob.*,o.paystate,o.address,o.mobile,o.cat_id,o.cat_name FROM " .$dou->table('order_booking'). " AS ob ".
         " LEFT JOIN " .$dou->table('order'). " o ON ob.order_no=o.order_no ".
         " $where ORDER BY bookdate ASC ";    
    // 分页
    $page = $check->is_number($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    $page_url = 'order_booking.php?1=1';
    $limit = $dou->pager_bysql($sql, 15, $page, $page_url, $get);

    $query = $dou->query($sql.$limit);
    while ($row = $dou->fetch_array($query)) {
        $add_time = date("Y-m-d H:i:s", $row['add_time']);
        $order_booking_list[$row[id]] = $row;
    }
    // 赋值给模板
    $smarty->assign('action_link', array (
            'text' => $_LANG['return_list'],
            'href' => 'javascript:history.back();' 
    ));
    $smarty->assign('user_id', $user_id);
    $smarty->assign('order_booking_list', $order_booking_list);
    $smarty->display('order_booking.htm');
}


elseif($rec == 'action') {

    if (is_array($_POST['checkbox'])) {
        $sql_in = $dou->create_sql_in($_POST['checkbox']);
        $action = $_POST['action'];
        //更新发货状态
        if ( in_array($action, array('noon_state','night_state')) ) {
            $dou->query("UPDATE " . $dou->table('order_booking') . " SET {$action} = '1' WHERE id {$sql_in}");
            $dou->dou_msg($_LANG['update_succes'], 'order_booking.php');
        }

        $dou->dou_msg($_LANG['select_empty']);

    } else {
        $dou->dou_msg($_LANG['date_select_empty']);
    }
}


?>